<?php

class FileController extends Zend_Controller_Action
{

    public function preDispatch()
    {
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            $this->_redirect('/');
        }
    }

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function uploadAction()
    {
        if ($this->_request->isPost()) {
            $form = new Application_Form_Upload();
            if ($form->isValid($_POST)) {
                $auth = Zend_Auth::getInstance();
                $username = $auth->getIdentity();
                if (!file_exists(APPLICATION_PATH . '/../files/' . $username . $form->getValue("path"))) {
                    mkdir(APPLICATION_PATH . '/../files/' . $username . $form->getValue("path"), 0777, True);
                }
                $form->file->setDestination(APPLICATION_PATH . '/../files/' . $username . $form->getValue("path"));
                $form->file->receive();
            }
        }
    }


}



